﻿using System;
using System.Data;
using System.Collections.Generic;
using Chenxin.Lib.Business.Entity;

namespace Chenxin.Lib.Business.BLL
{
    /// <summary>
    /// 业务逻辑类ContractAttachment 的摘要说明。
    /// </summary>
    public class ContractAttachment
    {
        public ContractAttachment()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(Guid RecordId)
        {
            return Chenxin.Lib.Business.DAL.ContractAttachment.Exists(RecordId);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Chenxin.Lib.Business.Entity.ContractAttachment model)
        {
            Chenxin.Lib.Business.DAL.ContractAttachment.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Chenxin.Lib.Business.Entity.ContractAttachment model)
        {
            Chenxin.Lib.Business.DAL.ContractAttachment.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(Guid RecordId)
        {

            Chenxin.Lib.Business.DAL.ContractAttachment.Delete(RecordId);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Chenxin.Lib.Business.Entity.ContractAttachment GetModel(Guid RecordId)
        {

            return Chenxin.Lib.Business.DAL.ContractAttachment.GetModel(RecordId);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return Chenxin.Lib.Business.DAL.ContractAttachment.GetList(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.Business.Entity.ContractAttachment> GetModelList(string strWhere)
        {
            DataSet ds = Chenxin.Lib.Business.DAL.ContractAttachment.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.Business.Entity.ContractAttachment> DataTableToList(DataTable dt)
        {
            List<Chenxin.Lib.Business.Entity.ContractAttachment> modelList = new List<Chenxin.Lib.Business.Entity.ContractAttachment>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Chenxin.Lib.Business.Entity.ContractAttachment model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Chenxin.Lib.Business.Entity.ContractAttachment();
                    if (dt.Rows[n]["RecordId"].ToString() != "")
                    {
                        model.RecordId = new Guid(dt.Rows[n]["RecordId"].ToString());
                    }
                    if (dt.Rows[n]["RelationId"].ToString() != "")
                    {
                        model.RelationId = new Guid(dt.Rows[n]["RelationId"].ToString());
                    }
                    model.Path = dt.Rows[n]["Path"].ToString();
                    model.FileName = dt.Rows[n]["FileName"].ToString();
                    model.Remark = dt.Rows[n]["Remark"].ToString();
                    if (dt.Rows[n]["UserId"].ToString() != "")
                    {
                        model.UserId = new Guid(dt.Rows[n]["UserId"].ToString());
                    }
                    model.UserName = dt.Rows[n]["UserName"].ToString();
                    if (dt.Rows[n]["DepartId"].ToString() != "")
                    {
                        model.DepartId = new Guid(dt.Rows[n]["DepartId"].ToString());
                    }
                    model.DepartName = dt.Rows[n]["DepartName"].ToString();
                    if (dt.Rows[n]["CompanyId"].ToString() != "")
                    {
                        model.CompanyId = new Guid(dt.Rows[n]["CompanyId"].ToString());
                    }
                    model.CompanyName = dt.Rows[n]["CompanyName"].ToString();
                    if (dt.Rows[n]["CityId"].ToString() != "")
                    {
                        model.CityId = new Guid(dt.Rows[n]["CityId"].ToString());
                    }
                    model.CityName = dt.Rows[n]["CityName"].ToString();
                    if (dt.Rows[n]["AttType"].ToString() != "")
                    {
                        model.AttType = int.Parse(dt.Rows[n]["AttType"].ToString());
                    }
                    if (dt.Rows[n]["AddTime"].ToString() != "")
                    {
                        model.AddTime = DateTime.Parse(dt.Rows[n]["AddTime"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        #endregion  成员方法
    }
}

